<template>
	<view style="width: 100vw;height: 100vh;background: #1E2238;color: white;" class="flex_column">
		<page-head style="padding: 10px 0;"></page-head>
		<view @click="show=false"
			style="width: 100vw;height: 100vh;background-color: #000000;opacity: 0.5;position: absolute;top: 0;left: 0;z-index: 99;"
			v-if="show"></view>
		<view style="padding: 0px 5vw ;">
			<view class="flex_row_between">
				<image @click="back" src="../../image/dbbtn/back.png" style="width: 8vh;height: 8vh;"></image>
				<view class="flex_row" style="justify-content: flex-end;">
					<image v-if="light" @click="light=false" src="../../image/dbbtn/ybd.png"
						style="width: 8vh;height: 8vh;" class=" between_padding">
					</image>
					<image v-else @click="light=true" src="../../image/twylt1/homeIcon/ybdbf.png"
						style="width: 8vh;height: 8vh;" class=" between_padding">
					</image>
					<image @click="navigateTo('/pages/set/set')" src="../../image/dbbtn/canshu.png"
						style="width: 8vh;height: 8vh;" class=" between_padding">
					</image>
				</view>
			</view>
		</view>
		<view class="flex_column" style="padding: 0 2vh;" v-if="!show">
			<view class="center_box">
				<view class="center_inbox">
					<view class="flex_row flex_wrap" style="padding:0 vh;">
						<view class="border_r10 flex_col_between item-con" v-for="(item,index) in listArr"
							:style="item.state?'opacity: 1;':'opacity: 0.3;'">
							<view class="flex_row_between">
								<image :src="item.src" style="width: 6vh;height: 6vh;"></image>
								<view style="width: 18vh;"></view>
								<image @click="show_set(item.setType)" v-if="item.tz" src="../../image/dbbtn/tiaozheng.png"
									style="width: 8vh;height: 8vh;">
								</image>
								<view v-else style="width: 8vh;"></view>
							</view>
							<view class="flex_row_between" style="padding-top: 5vw;">
								<view class="flex_column">
									<view class="rem04" style="color: white;">{{item.name}}</view>
									<view class="rem03" style="color: #FFF;opacity: 0.4;margin-top: 1.8vw;">
										{{item.underTxt}}
									</view>
								</view>
								<view class="flex_row" style="justify-content: flex-end;align-items: flex-end;">
									<image v-if="item.state" @click="item.state=false" src="../../image/dbbtn/open.png"
										style="height:2.5vw;width:6vw;">
									</image>
									<image v-else @click="item.state=true" src="../../image/dbbtn/close.png"
										style="height:2.5vw;width:6vw;">
									</image>
								</view>
							</view>
						</view>

					</view>
				</view>
			</view>
		</view>
		<view v-if="show" style="padding: 2vw 5vw;z-index: 999;">
			<view style="background: #4A5079;padding: 2.5vw 4vw;" class="border_r10 flex_col">
				<view class="flex_row_between alignCenter">
					<view class="flex_row alignCenter">
						<image @click="show=false" src="../../image/dbbtn/back.png" style="width: 8vh;height: 8vh;">
						</image>
						<view class="rem04" style="margin-left: 2vw;">{{list[setType].name}}</view>
					</view>
					<view>
						<image v-if="btnState" @click="btnState=false" src="../../image/dbbtn/open.png"
							style="height:4vh;width:9vh;">
						</image>
						<image v-else @click="btnState=true" src="../../image/dbbtn/close.png"
							style="height:4vh;width:9vh;">
						</image>
					</view>
				</view>
				<view class="flex_row_between" style="width: 100%;height: auto;">
					<view class="flex_col" style="padding-top: 1vh;">
						<view v-if="setType==0||setType==1" class="flex_row rem04 alignCenter">
							<view>运行时间</view>
							<view class="rem03" style="opacity: 0.4;margin-left: 1vw;">
								（设置{{list[setType].name}}在以下时间后自动关闭）</view>
						</view>
						<view v-if="setType==4" class="flex_row rem04 alignCenter">
							<view>延迟关闭</view>
							<view class="rem03" style="opacity: 0.4;margin-left: 1vw;">
								（设置消毒灯在以下时间后自动关闭）</view>
						</view>
						<view v-if="setType==0||setType==1||setType==4" class="rem03" style="margin:2vh 0;">快捷设置与手动输入
						</view>
						<view v-if="setType==3" class="rem03" style="margin-top: 2vh;">模式切换<text
								style="opacity: 0.4;margin-left: 15px;">（请选择舱内灯光模式，营造舒适的检测环境）</text></view>
						<view v-if="setType==3" class="flex_row" style="padding-top: 1.5vh;padding-bottom: 3vh;">
							<view v-for="(btn,i) in zmBtn" :class="i==zmIndex?'btn-sel':'btn-unsel'"
								@click="zmbtn_click(i)">{{btn}}</view>
						</view>
						<view v-if="setType==0||setType==1||setType==4" class="flex_row" style="padding: 0.3rem 0;">
							<view v-for="(item,index) in times"
								style="background: #646B97;width:8vw;height: 3vw;margin-right: 1.5vw;"
								class="allCenter border_r10 rem03" @click="changeTime(index)">{{item.text}}</view>
						</view>
						<view v-if="setType==0||setType==1||setType==4" class="flex_row" style="padding: 2.5vw 0;">
							<view class="flex_column allCenter">
								<image src="../../image/txxx/xialab.png"
									style="width: 2vw;height: 1vw;margin-bottom: 1vw;" @click="timeReduce(true)">
								</image>
								<swiper vertical="true" :current="hour" @change="changeHour" class="border_r10"
									style="width: 6vw;height: 4vw;background: #44CE7B;">
									<swiper-item v-for="(item,index) in 24" circular="true" class="rem04 allCenter"
										style="color: #000000;">
										{{(index)<10?'0'+index:index}}
									</swiper-item>
								</swiper>
								<image src="../../image/txxx/xiala.png" style="width:2vw;height: 1vw;margin-top: 1vw;"
									@click="timeAdd(true)">
								</image>
							</view>
							<view class="rem04 allCenter" style="height: 100%;width:1rem;height: 9vw;">:</view>
							<view class="flex_column allCenter">
								<image src="../../image/txxx/xialab.png"
									style="width: 2vw;height: 1vw;margin-bottom: 1vw;" @click="timeReduce(false)">
								</image>
								<swiper vertical="true" :current="min" @change="changeMin" class="border_r10"
									style="width: 6vw;height: 4vw;background: #44CE7B;">
									<swiper-item v-for="(item,index) in 60" circular="true" class="rem04 allCenter"
										style="color: #000000;">
										{{index<10?'0'+index:index}}
									</swiper-item>
								</swiper>
								<image src="../../image/txxx/xiala.png" style="width:2vw;height: 1vw;margin-top: 1vw;"
									@click="timeAdd(false)">
								</image>
							</view>
						</view>
					</view>
					<view v-if="setType==0"
						style="width: 1px;height: 20vw;border: 1px solid #383E62;margin-right: 2.5vw;"></view>
					<view v-if="setType==0" class="flex_column" style="width: 100%;">
						<view class="rem04">温度设定</view>
						<view class="allCenter rem08">23°C</view>
						<view class="allCenter rem03" style="opacity: 0.4;">实时温度</view>
						<SliderRange :max="50" blockColor="#44CE7B" :value="rangeVal" backgroundColor="#646B97"
							@change="handleRangeChange" :tipVisible="false">
						</SliderRange>
						<view style="font-size: 2.5vh;text-align: center;">调温（{{rangeVal[0]}}℃ - {{rangeVal[1]}}℃）
						</view>
					</view>
				</view>
				<view class="flex_row allCenter" style="margin-top: 2.5vw;">
					<view class="flex_row">
						<button style="background: #646B97;border-radius: 1vw;margin:0 2vw;" class="rem04"
							@click="show=false">
							<view style="padding: 0 3vh;">取消</view>
						</button>
						<button style="background: #44CE7B;border-radius: 1vw;color: #000000;margin:0 2vw;"
							class="rem04" hover-class="btnClick" @click="show=false">
							<view style="padding: 0 3vh;">确定</view>
						</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import SliderRange from '../../components/primewind-sliderrange/components/primewind-sliderrange/index.vue'
	export default {
		components: {
			SliderRange,
		},
		data() {
			return {
				light: false,
				show: false,
				hour: 0,
				min: 0,
				btnState: '',
				/**需要设置参数的类型:0 空调；1通风*/
				setType: 0,
				/**照明按钮*/
				zmBtn: ["暗", "亮", "全亮"],
				zmIndex: 0,
				rangeVal: [16, 28],
				listArr: [],
				list: [{
						src: require('../../image/twylt1/homeIcon/kt.png'),
						name: '空调',
						tz: true,
						underTxt: '舱内温度：23℃',
						state: true,
                        setType:0,
					},
					{
						src: require('../../image/twylt1/homeIcon/hq.png'),
						name: '通风',
						tz: true,
						underTxt: '清新空气',
						state: false,
                        setType:1,
					},
					{
						src: require('../../image/twylt1/homeIcon/fr.png'),
						name: '辅热',
						tz: false,
						underTxt: '舱内供暖',
						state: false,
                        setType:2,
					},
					{
						src: require('../../image/twylt1/homeIcon/zm.png'),
						name: '照明',
						tz: true,
						underTxt: '舱内泛光照明',
						state: false,
                        setType:3,
					},
					{
						src: require('../../image/twylt1/homeIcon/xd.png'),
						name: '消毒',
						tz: true,
						underTxt: '紫外消杀',
						state: false,
                        setType:4,
					},
					{
						src: require('../../image/twylt1/homeIcon/cm.png'),
						name: '舱门',
						tz: false,
						underTxt: '控制舱门',
						state: true,
                        setType:5,
					},
				],
				list2: [{
						src: require('../../image/twylt1/homeIcon/kt.png'),
						name: '空调',
						tz: true,
						underTxt: '舱内温度：23℃',
						state: true,
                        setType:0,
					},

					{
						src: require('../../image/twylt1/homeIcon/fr.png'),
						name: '辅热',
						tz: false,
						underTxt: '舱内供暖',
						state: false,
                        setType:1,
					},
					{
						src: require('../../image/twylt1/homeIcon/xd.png'),
						name: '消毒',
						tz: true,
						underTxt: '紫外消杀',
						state: false,
                        setType:4,
					},
					{
						src: require('../../image/twylt1/homeIcon/zm.png'),
						name: '照明',
						tz: true,
						underTxt: '舱内泛光照明',
						state: false,
                        setType:3,
					},


				],
				times: [{
						text: '15分钟',
						time: 15,
					},
					{
						text: '30分钟',
						time: 30,
					},
					{
						text: '1小时',
						time: 60,
					},
					{
						text: '2小时',
						time: 120,
					},
					{
						text: '3小时',
						time: 180,
					},
				],
			}
		},
		onShow: function() {
			getApp().globalData.type == 1 ? this.listArr = this.list2 : this.listArr = this.list;
			// this.open()
			// this.type = getApp().globalData.type;

			// console.log(getApp().globalData.type)
		},
		methods: {
			handleRangeChange(e) {
				this.rangeVal = e
			},
			zmbtn_click(i) {
				this.zmIndex = i
			},
			navigateTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			back() {
				uni.navigateBack({
					delta: 1,
				})
			},
			show_set(index) {
				this.setType = index;
				this.show = true;
			},
			changeHour(e) {
				this.hour = e.detail.current
			},

			changeMin(e) {
				this.min = e.detail.current
			},

			changeTime(index) {
				var hour = 0;
				var min = 0;
				if (this.times[index].time >= 60) {
					hour = this.times[index].time / 60;
					min = this.times[index].time % 60;
				} else {
					hour = 0;
					min = this.times[index].time;
				}
				this.hour = hour;
				this.min = min
			},

			timeAdd(e) {
				if (e) {
					if (this.hour < 23) {
						this.hour++
					} else {
						this.hour = 0
					}
				}
				if (!e && this.hour < 23) {
					if (this.min == 59) {
						this.min = 0;
						this.hour++
					} else {
						this.min++
					}
				}
			},

			timeReduce(e) {
				if (e) {
					if (this.hour > 0) {
						this.hour--
					} else {
						this.hour = 23
					}
				}
				if (!e) {
					if (this.min == 0) {
						this.min = 59;
						if (this.hour != 0) {
							this.hour--
						}
					} else {
						this.min--
					}
				}
			}
		}
	}
</script>

<style scoped>
	/* page {
		background: #1E2238;
	} */

	.btnClick {
		background: #36BB6B !important;
	}

	.item-con {
		/* 	height: 3rem;
		width: 4.4rem; */
		margin: 2vh;
		padding: 3vh;
		background-color: #4A5079;
	}

	.btn-sel {
		background: #44CE7B;
		border-radius: 0.3rem;
		overflow: hidden;
		width: 20vh;
		height: 20vh;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 5vh;
		color: #000000;
		line-height: 1;
		margin-right: 2.5vw;
	}

	.btn-unsel {
		background: #646B97;
		border-radius: 0.3rem;
		overflow: hidden;
		width: 20vh;
		height: 20vh;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 5vh;
		margin-right: 2.5vw;
		line-height: 1;
	}

	.center_box {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
	}

	.center_inbox {
		/* border: 1px solid pink; */
		width: 126vh;
	}
</style>
